﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LarasMutiaraDiva.SkripsiLaras.Lib
{
    static class MyClass
    {
        public static string TakeBefore(this string input, int current, int n)
        {
            if (current < n)
                n = current;

            string temp = string.Empty;

            while (n != 0)
            {
                temp += input[current - n];
                n--;
            }

            return temp;
        }
        public static string TakeAfter(this string input, int current, int n)
        {
            if (input.Length - 1 == current)
            {
                return "\n";
            }

            if (current + n > input.Length - 1)
                n = input.Length - current - 1;

            string temp = string.Empty;
            int i = current + 1;
            while (i <= current + n)
            {
                temp += input[i];
                i++;
            }

            return temp;
        }

        public static bool isNumber(this string inputString)
        {
            bool number = true;
            if (inputString == string.Empty)
                number = false;
            /*
            foreach (var myChar in inputString)
            {
                if(number)
                    number = Char.IsNumber(myChar);
            }
            */

            for (int i = 0; i < inputString.Length && number; i++)
            {
                number = Char.IsNumber(inputString[i]);
                //Console.WriteLine(i);
            }
            return number;
        }

        public static int GetIndex(this List<string> terms, string value)
        {
            int index = 0;
            foreach (var term in terms)
            {
                if (term.Equals(value))
                    return index;

                index++;
            }
            return -1;
        }

        public static Dictionary<int,double> toDictionary(this double[] myArray)
        {
            var myDictionary = new Dictionary<int, double>();
            for (int i = 0; i < myArray.Count(); i++)
            {
                myDictionary.Add(i, myArray[i]);
            }

            return myDictionary;
        }
    }
}
